import TicketForm from "@/components/ui/Forms/TicketForm/TicketForm";
import {getObj} from "@/services/api_service";
import React, {useEffect, useState} from "react";

type TypeVehicleOption = {
    value: string;
    label: string;
};

export default function ClientTicketForm({setModalOpen}: {
    setModalOpen: React.Dispatch<React.SetStateAction<boolean>>
}) {
    const [
        vehicleOptions,
        setVehicleOptions
    ] = useState<TypeVehicleOption[]>([]);

    useEffect(() => {
        const fetchVehicles = async () => {
            try {
                const userData = await getObj('/api/auth/get-user-data/');
                setVehicleOptions(userData?.vehicles.map((vehicle: any) => ({
                    value: vehicle.id,
                    label: `${vehicle.registration_number} (${vehicle.vehicle_type})`
                })));
            } catch (error) {
                console.error('Ошибка при получении списка транспортных средств:', error);
            }
        };

        fetchVehicles();
    }, []);

    return (
        <TicketForm
            setModalOpen={setModalOpen}
            vehicleOptions={vehicleOptions}
            showVehicleOptions={false}
            showQrCode={false}
        />
    );
}